﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using He.Web.UI;
using He.API.WeiXin;

namespace He.Web.manage.weixin
{
    public partial class group_msg : Manage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                GroupBind();
            }
        }

        #region 分组绑定=================================
        private void GroupBind()
        {
            ddlGroupId.DataSource = GroupHandle.GetGroups();
            ddlGroupId.DataTextField = "Value";
            ddlGroupId.DataValueField = "Key";
            ddlGroupId.DataBind();
        }

        #endregion

        protected void btnSend_Click(object sender, EventArgs e)
        {
            string group_id = ddlGroupId.SelectedValue;
            //获取要发送的文章列表
            string aids = this.hidArticleIds.Value;
            List<Model.article> lst = new BLL.article().GetModelList(string.Format("id in ({0})", aids));
            //上传图文素材
            string media_id = UploadHandle.UploadArticle(lst);
            //开始群发
            int errcode = MutiMsgHandle.Send(group_id, media_id, API.WeiXin.Enums.MsgType.mpnews.ToString());
            if (errcode == 0)
            {
                ShowSuccess("消息群发成功啦！", Request.RawUrl);
            }
            else
            {
                ShowError("群发失败，错误代码:" + errcode);
            }
        }
    }
}